package com.example.recall_application.app.utils;


import com.jess.arms.mvp.IView;
import com.jess.arms.utils.RxLifecycleUtils;

import io.reactivex.SingleTransformer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by yifan.jiang on 2017/11/7.
 */

public class RxHelper {


    public static <T> SingleTransformer<T, T> io_main(IView v) {
        //隐藏下拉刷新的进度条
        return upstream ->
                upstream.subscribeOn(Schedulers.io())
                        .doOnSubscribe(disposable -> {
                            v.showLoading();//显示下拉刷新的进度条
                        })
                        .observeOn(AndroidSchedulers.mainThread())
                        .compose(RxLifecycleUtils.bindToLifecycle(v))
                        .doFinally(v::hideLoading);
    }

//    public static <T> SingleTransformer<T, T> io_main_page(IRecycleView v, boolean pullToRefresh) {
//        //隐藏下拉刷新的进度条
//        return upstream ->
//                upstream.subscribeOn(Schedulers.io())
//                        .doOnSubscribe(disposable -> {
//                            if (pullToRefresh) v.showLoading();//显示下拉刷新的进度条
//                            else v.startLoadMore();
//                        })
//                        .observeOn(AndroidSchedulers.mainThread())
//                        .compose(RxLifecycleUtils.bindToLifecycle(v))
//                        .doFinally(() -> {
//                            if (pullToRefresh) v.hideLoading();
//                            else v.endLoadMore();
//                        });
//    }
}
